import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React from "react";
import classes from "./chainSwitchNft.module.less";
import { useDispatch, useSelector } from "react-redux";
import { useLocalStorageSetState } from "../../hooks";
import classNames from "classnames";
import { jsx as _jsx } from "react/jsx-runtime";
function ChainSwitchNft(props) {
    var theme = useSelector(function(Rstate) {
        return Rstate.app.theme;
    });
    var chainNft = useSelector(function(Rstate) {
        return Rstate.app.chainNft;
    });
    var chainList = useSelector(function(Rstate) {
        return Rstate.app.chainList;
    });
    var dispatch = useDispatch();
    var _useLocalStorageSetState = _sliced_to_array(useLocalStorageSetState(), 2), setLocalState = _useLocalStorageSetState[1];
    // const active = useRef<number>(chainList.indexOf(chain) || 0);
    // const next = () => {
    //   const newActive = active.current + 1;
    //   if (newActive > chainList.length - 1) {
    //     active.current = 0;
    //   } else {
    //     active.current = newActive;
    //   }
    //   dispatch.app.SET_CHAIN_NFT(chainList[active.current]);
    //   setLocalState({
    //     chain: chainList[active.current],
    //   });
    //   props.onChainChange?.(chainList[active.current]);
    // };
    var changeChain = function(newChian) {
        var _props_onChainChange;
        if (newChian === chainNft) return;
        dispatch.app.SET_CHAIN_NFT(newChian);
        setLocalState({
            chainNft: newChian
        });
        (_props_onChainChange = props.onChainChange) === null || _props_onChainChange === void 0 ? void 0 : _props_onChainChange.call(props, newChian);
    };
    return /*#__PURE__*/ _jsx("div", {
        className: classNames(classes.chain_switch, props.className),
        children: /*#__PURE__*/ _jsx("div", {
            className: classes.chain_container,
            children: chainList.map(function(chainN) {
                return /*#__PURE__*/ _jsx("div", {
                    onClick: function() {
                        changeChain(chainN);
                    },
                    className: classNames(classes.chain_item, chainNft === chainN ? classes.active_item : ""),
                    children: /*#__PURE__*/ _jsx("span", {
                        children: chainN
                    })
                }, chainN);
            })
        })
    });
}
export default ChainSwitchNft;

 //# sourceMappingURL=index.js.map